<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>React02</title>

</head>

<body>
  <div class="container"></div>
  <hr>
  <div class="container2"></div>
  <hr>
  <div class="container3"></div>
  <!-- react核心库 -->
  <script src="./js/react.development.js"></script>
  <!-- react拓展库 用于支持react操作dom -->
  <script src="./js/react-dom.development.js"></script>
  <script src="./js/prop-types.js"></script>
  <script src="./js/babel.min.js"></script>

  <script type="text/babel">
    class Person extends React.Component {
      render() {
        return (
          <ul>
            <li>姓名: {this.props.name}</li>
            <li>年龄: {this.props.age + 1}</li>
            <li>性别: {this.props.sex}</li>
          </ul>
        )
      }

      // props是只读的

      // 类型 必要性设置
      static propTypes = {
        name: PropTypes.string.isRequired,
        sex: PropTypes.string,
      }

      // 默认值
      static defaultProps = {
        sex: 'nonmale',
        age: 18
      }

    }


    let obj = {
      name: 'Jetwang',
      age: 25,
      sex: 'male'
    }
    // ReactDOM.render(<Person name="tom" age="18" sex="male" />, document.querySelector('.container3'))
    ReactDOM.render(<Person name="tom" />, document.querySelector('.container3'))
    ReactDOM.render(<Person {...obj} />, document.querySelector('.container2'))
  </script>
</body>

</html>